<template>
  <div class="container">  
    <div class="content">
      <div class="table">
        <el-table
          :data="traineeList"
          style="width: 100%"
          :default-sort = "{prop: 'date', order: 'descending'}"
          >
          <el-table-column
            prop="traineeName"
            label="学员姓名"
            align="center"
            width="180">
          </el-table-column>
          <el-table-column
            prop="trainee"
            label="学员ID"
            align="center"
            width="300">
          </el-table-column>
          <el-table-column
            prop="telephone"
            label="教练电话"
            align="center"
            >
          </el-table-column>
          <el-table-column
            prop="attendTime"
            label="预约时间段"
            align="center"
            >
          </el-table-column>
          <el-table-column
            prop="catogary"
            label="科目类别"
            align="center"
            >
          </el-table-column>
          <el-table-column
            prop="coach"
            label="教练ID"
            width="300"
            align="center"
            >
          </el-table-column>
          <el-table-column
            prop="create_time"
            label="预约时间"
            align="center"
            sortable
            >
          </el-table-column>
          <el-table-column
            label="状态"
            align="center"
            >
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status === 'Finish'" type="success">已完成</el-tag>
              <el-tag v-if="scope.row.status === 'cancel'" type="danger">已取消</el-tag>
              <el-tag v-if="scope.row.status === 'progress'" >进行中</el-tag>
            </template>
          </el-table-column>
          <el-table-column width="140" align="center" label="操作">
            <template slot-scope="scope">
              <el-button
              type="text"
                @click="handleEdit(scope.row)" :disabled="scope.row.status !== 'progress'">完成</el-button>
                <el-button
              type="text" :disabled="scope.row.status !== 'progress'"
                @click="handleCancel(scope.row)">取消</el-button>
              <el-button
                type="text"
                @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import trainee from '@/api/trainee'
export default {
  data() {
    return {
      traineeList:[],
      pageSize:10,
      pageNum:1,
      pageTotal:0,
    }
  },
  mounted(){
    this.getAllTrainee(1)
  },
  methods: {
    handleCancel(row){
      trainee.cancelStatus(row.id).then(res => {
        if(res.code === 0){
          this.$message.success('success')
          this.getAllTrainee(this.pageNum)
        }else{
          this.$message.error('error')
        }
      })
    },
    handleEdit(row){
      trainee.updateStatus(row.id).then(res => {
        if(res.code === 0){
          this.$message.success('success')
          this.getAllTrainee(this.pageNum)
        }else{
          this.$message.error('error')
        }
      })
    },
    handleDelete(row){
      trainee.deleteTrainee(row.id).then(res => {
        if(res.code === 0){
          this.$message.success('success')
          this.getAllTrainee(this.pageNum)
        }else{
          this.$message.error('error')
        }
      })
    },
    getAllTrainee(value){
      let questBody = {
        pageSize:this.pageSize,
        pageNum:value,
      }
      trainee.getAllTrainee(questBody).then(res => {
        console.log(res);
        if(res.code === 0){
          this.traineeList = res.data.list
          this.pageNum = value
          this.pageTotal = res.data.Total
        }else{
          this.$message.error('error')
        }
      })
    }
  }
}
</script>

